<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /* 
      Object.defineProperty(obj,propName,{})
        - 主要是对一个已经存在的对象中的属性进行修改
      */

      const obj = {
        name: "laowang",
        age: 18,
      };

      //修改obj中的name属性的 特性
      Object.defineProperty(obj, "name", {
        value: "laowang",
        writable: false,
        enumerable: false,
        configurable: false,
      });

      obj.name = "lily";
      console.log(obj);

      //getter函数和setter函数(存取器属性)
      Object.defineProperty(obj, "age", {
        get() {
          console.log("获取值了");
          return 18;
        },
        set(newValue) {
          console.log("值更信息了");
        },
      });

      obj.age++;
    </script>
  </body>
</html>
